package com.example.lp.lpuicore.anim;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;

import com.example.lp.lpuicore.R;

/**
 * Author by lp,on 2021/7/1/001,14:22.
 * view动画
 */
public class ViewAnimFragment extends BaseFragment {

    @Override
    int getFragmentLayoutId() {
        return R.layout.fragment_view_amin;
    }

    @Override
    String getTitle() {
        return "view动画";
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        initView();
        return view;
    }

    private void initView() {
        getFragmentView().findViewById(R.id.btn_translation_xml).setOnClickListener(v -> {
            Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.trans_anim);
            baseAnimView.startAnimation(animation);
        });

        getFragmentView().findViewById(R.id.btn_translation).setOnClickListener(v -> {
            TranslateAnimation animation = new TranslateAnimation(0, 500,0, 100);
            animation.setDuration(500);
            baseAnimView.startAnimation(animation);
        });
        getFragmentView().findViewById(R.id.btn_rotate).setOnClickListener(v -> {
            RotateAnimation animation = new RotateAnimation(0, 500);
            animation.setDuration(500);
            baseAnimView.startAnimation(animation);
        });
        getFragmentView().findViewById(R.id.btn_scale).setOnClickListener(v -> {
            ScaleAnimation animation = new ScaleAnimation(1,1.5f,1,1.5f);
            animation.setDuration(500);
            baseAnimView.startAnimation(animation);
        });
        getFragmentView().findViewById(R.id.btn_alpha).setOnClickListener(v -> {
            AlphaAnimation animation = new AlphaAnimation(0.1f,1f);
            animation.setDuration(500);
            baseAnimView.startAnimation(animation);
        });

        getFragmentView().findViewById(R.id.btn_all).setOnClickListener(v -> {
            Animation animation = AnimationUtils.loadAnimation(getContext(), R.anim.together_anim);
            baseAnimView.startAnimation(animation);
        });

    }
}
